//- 面包屑
ul.breadcrumb
	li
		a(href='/portal/index') 首页
	li.sep >
	li.cd 服务产品


cache = {}
all = []
each category in items
	title = category.title
	rawItems = category.items
	push = Array.prototype.push

	list = []
	if rawItems && rawItems.length
		each product in rawItems
			if Array.isArray(product.items)
				- push.apply(list, product.items)
			else
				- list.push(product)

	- list.sort(function(a, b) {return b.hot - a.hot})
	- cache[title] = list
	- push.apply(all, list)

//- all用户广告，广告先写死
- all.sort(function(a, b) {return b.hot - a.hot})
.serviceAd
	.gf-ad(datasource='ad/list?code=service')

mixin tdcontent(p)
	unless p
		- return

	pricing = p.pricing[0]
	div(ng-init='__options#{p.product_id}=false')
		.options.border(id='options#{p.product_id}', ng-show='__options#{p.product_id}', ng-mouseover='__options#{p.product_id}=true', ng-mouseout='__options#{p.product_id}=false')
			.wborder(style='top: -1px;_top: -5px;left: 0px;width:63px;height:1px;*height:5px;')
			a.option.link(ng-hide="serviceOrder.exists['#{p.product_id}']", href='javascript:void(0)', ng-click="ServiceTip=true;buy(#{JSON.stringify(p)})")
				.ib.mright15 立即购买
				&gt;
			a.option.link.btopdashed(ng-hide="cart.exists['#{p.product_id}']", href='javascript:void(0)', ng-click="$parent.addToCart({product_id: '#{p.product_id}', period: #{pricing.period}, count: 1, payment_type: 1})")
				.ib.mright5 加入购物车
				&gt;
			a.option.link.btopdashed(ng-show="cart.exists['#{p.product_id}']", href='#/cart')
				.ib.mright5 查看购物车
				&gt;
		.box
			a(href='#/service/detail?pid=#{p.product_id}', title='#{p.title}')
				img.s66.logo.logoie6(src='img/blank.gif', gf-src='/_image/pdt_service_#{p.product_id}', alt=p.title)
			.col
				product_title = p.title
				pos = product_title.indexOf('（')
				pos = pos > -1 ? pos : product_title.indexOf('(')
				cls = pos > -1 ? 'tac' : 'one'
				h3.nomp(class='#{cls}')
					a(href='#/service/detail?pid=#{p.product_id}', title='#{p.title}')
						if pos > -1
							| #{product_title.substr(0, pos)}
							br
							| #{product_title.substring(pos, product_title.length)}
						else
							| #{p.title}
				.afc.mtop10.one.tal(title=p.description) !{p.description||'&nbsp;'}
				.yui3-g.mtop10
					.yui3-u-1-2
						span
							span.font16.dig= pricing.price
							span.g 元/#{periodLabel[pricing.period]}
					unless p.offline
						.yui3-u-1-2(ng-mouseleave='__options#{p.product_id}=false')
							.prebuy.ib.lbc.cp(ng-class='{active19: __options#{p.product_id}}', ng-hide="serviceOrder.exists['#{p.product_id}']", href='javascript:void(0)',  gf-init-pos='#options#{p.product_id}', ng-mouseenter='__options#{p.product_id}=true')
								.ib.mright8.vam 购买
								.ib.buyArrow2.arrowDown123.vam(ng-class="{arrowUp123: __options#{p.product_id}}")

							//- a.link(ng-show="serviceOrder.exists['#{p.product_id}']",href='javascript:void(0)', ng-click="ServiceTip=true;buy(#{JSON.stringify(p)});") 续订&nbsp;&gt;

					else
						.yui3-u-1-2
							a.link(title='简单登记您的信息，我们的工作人员将协助您完成购买', id='sid#{p.product_id}', href='javascript:void(0)', ng-click="huihu('#{p.product_id}', #{pricing.period}, '#{p.title}')") 登记购买&nbsp;&gt;

periodLabel = ['', '月','季','半年','年']
each sect,index in ['财经资讯', '顾问组合', '投资建议']
	section.mtop30.serhomesect
		h2.nomp
			.ib.vab
				img.secicon(src='img/blank.gif', class='icon'+index).mright5
				| #{sect}&nbsp;
			if index == 1
				.ib.vab.discount

		items = cache[sect]
		if items
			p = items[0]
			pricing = p.pricing[0]
			table.mtop5.lay
				tr(ng-init='__options#{p.product_id}=false')
					td(colspan=2, rowspan=2).tal
						unless p.offline
							.options.border(id='options#{p.product_id}', ng-show='__options#{p.product_id}', ng-mouseover='__options#{p.product_id}=true', ng-mouseout='__options#{p.product_id}=false')
								a.option.link(ng-hide="serviceOrder.exists['#{p.product_id}']", href="javascript:void(0)", ng-click="ServiceTip=true;buy(#{JSON.stringify(p)})")
									.ib.mright15 立即购买
									&gt;
								a.option.link.btopdashed(ng-hide="cart.exists['#{p.product_id}']", href='javascript:void(0)', ng-click="$parent.addToCart({product_id: '#{p.product_id}', period: #{pricing.period}, count: 1, payment_type: 0})")
									.ib.mright5 加入购物车
									&gt;
								a.option.link.btopdashed(ng-show="cart.exists['#{p.product_id}']", href='#/cart')
									.ib.mright5 查看购物车
									&gt;
						.box.big
							a(href='#/service/detail?pid=#{p.product_id}', title='#{p.title}')
								img.s66.logo(src='img/blank.gif', gf-src='/_image/pdt_service_#{p.product_id}', alt=p.title)
							.col
								a.font16.b(href='#/service/detail?pid=#{p.product_id}', title='#{p.title}')= p.title

								promotion = p.promotion.split('。')
								detail = promotion.slice(0, -1).join('。')
								qtip = promotion.slice(-1)
								.mtop8.tal
									a.b(gf-multiellipsis, fixed-height=57, href='#/service/detail?pid=#{p.product_id}', title='#{detail}') #{detail}
								.mtop10.tip.oneline(title=qtip) #{qtip}
							.bar
								.inner.yui3-g
									.yui3-u-1-2.tac
										span.dig.font24= pricing.price
										| &nbsp;
										span.g 元/#{periodLabel[pricing.period]}
									.yui3-u-1-2.tar(ng-mouseleave='__options#{p.product_id}=false')
										if p.offline
											a.link.ib.servbuy.mrem2(title='简单登记您的信息，我们的工作人员将协助您完成购买', id='sid#{p.product_id}', href='javascript:void(0)', ng-click="huihu('#{p.product_id}', #{pricing.period}, '#{p.title}')")
												.ib.mright8 登记购买
												.ib.buy-arrow.vam
										else
											a.ib.servbuy.mrem2(ng-hide="serviceOrder.exists['#{p.product_id}']", href='javascript:void(0)', gf-init-pos='#options#{p.product_id}', line-height=28, ng-mouseenter='__options#{p.product_id}=true')
												.ib.mright8 购买
												.ib.buy-arrow.vam(ng-class="{'arrow-up': __options#{p.product_id}, 'arrow-down': !__options#{p.product_id}}")

											//- a.link.ib.servbuy.mrem2(ng-show="serviceOrder.exists['#{p.product_id}']", href='javascript:void(0)', ng-click="ServiceTip=true;buy(#{JSON.stringify(p)});")
											//-	.ib.mright8 续订
											//-	.ib.buy-arrow.vam

					td
						mixin tdcontent(items[1])
					td.gr
						mixin tdcontent(items[2])
				tr
					td
						mixin tdcontent(items[3])
					td.gr
						mixin tdcontent(items[4])

				subarray = items.slice(5)
				rownum = Math.ceil(subarray.length/4)
				i = 0
				while i < rownum
					base = i*4
					tr
						td
							mixin tdcontent(subarray[base])
						td.gr
							mixin tdcontent(subarray[base+1])
						td
							mixin tdcontent(subarray[base+2])
						td.gr
							mixin tdcontent(subarray[base+3])
					- i++

each sect,index in ['账户提示', '个股资讯', '市场预警']
	section.mtop30.serhomesect(ng-init='tab#{index}=true')
		h2.nomp(style='padding-bottom: 8px;', ng-class='{bbottom: !tab#{index}}', ng-switch='tab#{index}')
			a(ng-switch-when='false', href='javascript:void(0)', ng-click='$parent.tab#{index}=true').pull-right.font12.dc.nor.mrem.ahover
				.ib.mright8 展开
				.ib.zhankai

			a(ng-switch-when='true', href='javascript:void(0)', ng-click='$parent.tab#{index}=false').pull-right.font12.dc.nor.mrem.ahover
				.ib.mright8 收起
				.ib.shouqi

			img.secicon(src='img/blank.gif', class='icon'+(index+3)).mright5
			= sect
		items = cache[sect]

		table(ng-show='tab#{index}')
			colgroup
				col(style='width:5em')
				col
				col
				col(style='width:10em;')
				col(style='width:10em;')
			thead
				tr
					th 序号
					th 产品名称
					th 产品特色
					th 产品价格
					th 操作
			tbody
				if items
					each p,i in items
						tr(class=i%2?'even':'')
							td.vc= i+1
							td.vc
								a(href='#/service/detail?pid=#{p.product_id}').link.bc= p.title

							//- 过滤最后的中文句号
							d = p.description
							len = d.length
							if d.charAt(len-1) == '。'
								- d = d.substr(0, len-1);
							td.bc.tal= d

							td.vc
								pricing = p.pricing[0]
								span.dig= Number(pricing.price).toFixed(2)
								span.g 元/#{periodLabel[pricing.period]}
							td.vc
								unless p.offline
									a.link(ng-hide="serviceOrder.exists['#{p.product_id}']", href='javascript:void(0)', ng-click="purchase('#{p.product_id}', #{pricing.period}, 1, 1, #{JSON.stringify(p)})") 购买&nbsp;»
									//- a.link(ng-show="serviceOrder.exists['#{p.product_id}']", href='javascript:void(0)', ng-click="ServiceTip=true;buy(#{JSON.stringify(p)});") 续订&nbsp;»
								else
									a.link(id='sid#{p.product_id}', href='javascript:void(0)', ng-click="huihu('#{p.product_id}', #{pricing.period}, '#{p.title}')") 购买&nbsp;»

.pad10
//- 回呼购买对话框
div(ng-switch='purchaseDialog', ng-show='online')
	.dialog(ng-switch-when='true', ng-controller='App.DialogController', ng-style="{top: top+'px', left: left+'px'}", id='purchaseDialog').border
		.close(ng-click='close()') &nbsp;
		.title.font16.cm(gf-move-dialog='#purchaseDialog') {{product.title}}
		.pad15
			.pad30.nc(ng-show='dialogState[product.id]==1') 
				.alert.pull-left.mrem
				span.font14 提交成功，我们的顾问将与您取得联系，感谢您的信任！
				.mtop30.tac
					button.btn.primary(ng-click='close()') 确定
			div(ng-hide='dialogState[product.id]==1')
				.mbottom20.nc.font14 我们将对您的信息严格保密，您的信息将不会被用于其它任何用途。
				form(name='dform', ng-submit='submit()')
					.mbottom20
						label(for='dialog_id_1').w5em 
							span.red *
							| 姓名
						input(id='dialog_id_1', gf-input, name='fullname', ng-model='param.fullname', required).text
						.yes(ng-show='param_fullnameError==2')
						.no(ng-show='param_fullnameError==1')
					.mbottom20
						label(for='dialog_id_2').w5em 
							span.red *
							| 手机号
						input(id='dialog_id_2', gf-input, name='mobile', ng-model='param.mobile', required).text
						.yes(ng-show='param_mobileError==2')
						.no(ng-show='param_mobileError==1')
						
					.mbottom30
						label.w5em &nbsp;
						input(type='submit', value='提交', ng-disabled='!dform.$valid').btn.primary
						span(ng-show='error').nc {{error}}

.dialog.border.g.gf-dialog.hidden(fixed=1, ng-show='ServiceTip', gf-remove-class='hidden')
	.close(ng-click='ServiceTip=false', title='关闭') &nbsp;
	.title.font16 {{product.title}}
	.pad15
		div
			b 产品名称：
			| {{product.name}}

		.mtop10
			b 购买周期：
			span(ng-switch='pricing.length')
				span(ng-switch-when=1, ng-bind='periodLabel[1]')
				span(ng-switch-default)
					select(ng-hide='serviceOrder.exists[product.product_id]', ng-options='t as periodLabel[t.period] for t in pricing', ng-model='$parent.period', style='width: 5em;')
					span(ng-show='serviceOrder.exists[product.product_id]', ng-bind='periodLabel[serviceOrder.exists[product.product_id].djzq]')

		.mtop10(ng-switch='product.zhid')
			b 购买数量：
			select(ng-switch-when='false', ng-options='n for n in range(period.period)', ng-model="$parent.number", style='width: 5em;')
			select(ng-switch-when='true', ng-options='n for n in range(period.period).slice(0, 5)', ng-model="$parent.number", style='width: 5em;')
	
		.mtop10.border.pad10.boxbg
			span.mrem2 已选择: {{product.title}}
				| 总价
				span.mlem.rc ￥{{period.price*number}}
			
			.mbottom10(ng-switch='!!serviceOrder.exists[product.product_id]')
				button(ng-switch-when='false', ng-hide='product.offline', ng-click='purchase(product.product_id, period.period, number, paymentType, product);ServiceTip=false;').btn.primary.mtop10.mlem 立即购买
				//- button(ng-switch-default, ng-hide='product.offline', ng-click='purchase(product.product_id, serviceOrder.exists[product.product_id].djzq, number, 2, product)').btn.primary.mtop10.mlem 我要续订
